package com.asen.commons.core.base.model;

import com.asen.commons.utils.JsonUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;

public class JsonObject extends HashMap<String, Object> implements Cloneable {
    public JsonObject() {
    }

    public String getString(String key) {
        Object value = this.get(key);
        return value == null ? null : value.toString();
    }

    public Date getDate(String key) {
        Object value = this.get(key);
        return JsonUtils.castToDate(value);
    }

    public Boolean getBoolean(String key) {
        Object value = this.get(key);
        return value == null ? null : JsonUtils.castToBoolean(value);
    }

    public Long getLong(String key) {
        Object value = this.get(key);
        return JsonUtils.castToLong(value);
    }

    public Integer getInteger(String key) {
        Object value = this.get(key);
        return JsonUtils.castToInt(value);
    }

    public BigDecimal getBigDecimal(String key) {
        Object value = this.get(key);
        return JsonUtils.castToBigDecimal(value);
    }

    public Object clone() {
        JsonObject jsonObject = (JsonObject)super.clone();
        return jsonObject;
    }

    public boolean equals(Object o) {
        boolean equals = super.equals(o);
        return equals && this.size() == 0 && this != o ? false : equals;
    }
}
